import { defineStore } from 'pinia';
import { storage } from '@/utils/Storage';

export type IEditorMdState = {
  content: string; // 临时保存尚未上传的文件内容
};

const contentKey = 'editor-md-content';

export const useEditorMdStore = defineStore({
  id: 'app-editorMd',
  state: (): IEditorMdState => ({
    content: storage.get(contentKey, ''),
  }),
  getters: {
    getContent(): string {
      return this.content;
    },
  },
  actions: {
    setContent(content: string) {
      this.content = content;
      storage.set(contentKey, content)
    },
  },
});
